package br.ufpi.hu.prescricao.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Hashtable;
import java.util.Properties;
import java.util.Set;

public class LoadResourceHelper {

	private ClassLoader classLoader;

	public LoadResourceHelper() throws IOException {}
	
	public void setClassLoader(ClassLoader classLoader) {
		this.classLoader = classLoader;
	}

	public Hashtable<String, String> carregarResource(String file) throws IOException {
		
		Hashtable<String, String> resources;


		resources = new Hashtable<String, String>();

		if (classLoader == null) {
			classLoader = this.getClass().getClassLoader();
		}
		
		InputStream fileStream = classLoader
				.getResourceAsStream(file);

		Properties props = new Properties();
		props.load( fileStream );

		Set<Object> keys = props.keySet();

		for (Object object : keys) {

			String key = (String)object; 

			String value = (String) props.get(object);

			resources.put(key, value);

		}
		
		return resources;

	}

}
